(() => {
  let ele = {};
  ele.more = $("#more");
  ele.empty = $("#empty");
  ele.meiyou = $("#meiyou");
  ele.list_son = $("#list_son");
  let list = [];
  let page = 1;
  // !发请求
  asyncList();
  function asyncList() {
    let token = getCookie("token");
    ajax({
      method: "get",
      url: API_PATH.SERVICE_DIAO,
      header: {
        Authorization: token,
      },
      data: {
        page: page,
      },
      success: (res) => {
        if (res.code == 1) {
          //   obj = res.data.detail;
          list = [...list, ...res.data.data];
          if (list.length === 0) {
            page = 0;
            ele.more.style.display = "none";
            ele.empty.style.display = "block";
          } else {
            initList();
            page++;
            if (page > res.data.last_page) {
              ele.more.innerText = "没有更多了";
              ele.more.onclick = null;
            } else {
              ele.more.innerText = "加载更多";
              ele.more.onclick = () => asyncList(page);
            }
          }
        } else openTips(res.msg);
        initList();
      },
      error: (err) => {
        // openTips(err.msg);
      },
    });
  }
  // 渲染数据
  function initList() {
    let newList = list
      .map((item) => {
        return `  <div class="list">
                            <div class="center">
                                <div class="centerin">
                                    <img src="${
                                      item.agent_info &&
                                      item.agent_info.head_pic
                                        ? IMG_DOMAIN + item.agent_info.head_pic
                                        : item.agent_info.sex == 1
                                        ? "http://img.qxgs.cc/tiantianlaishouzu/img/my/tx1.png"
                                        : "http://img.qxgs.cc/tiantianlaishouzu/img/my/tx2.png"
                                    }" alt="" />
                                </div>
                                <p>${
                                  item.agent_info && item.agent_info.nick_name
                                    ? item.agent_info.nick_name
                                    : "空"
                                }</p>
                            </div>
                            <div class="time">${
                              item.created_at.split(" ")[0]
                            }</div>
                            <div class="right">
                                <img src="${
                                  IMG_DOMAIN + item.house_info.logo
                                }" alt="">
                                <p>x${Number(item.money).toFixed(0)}</p>
                            </div>
                        </div>`;
      })
      .join(" ");
    ele.list_son.innerHTML = newList;
  }
})();
